//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    loading:false,
    indicatorDots: true,
    autoplay: false,
    interval: 5000,
    duration: 1000,
    banner: [],
    goods8: [],
    goods4: [],
    goodsList:[]
  },
  clickSwiperImage(event){

    const title = event.currentTarget.dataset.title;
    const val = event.currentTarget.dataset.val;

    let url="";
    const flag=isNaN(Number(val));
    if(flag){
      url = `/pages/webview/webview?title=${title}&href=${val}`
    }else{
      url = `/pages/goods/goods?id=${val}`
    }


    wx.navigateTo({
      url: url
    })
  },
  clickSearchBtn(){
    wx.navigateTo({
      url: '/pages/class/class'
    })
  },
  clickSearchInput(){
    wx.navigateTo({
      url: '/pages/search/search'
    })
  },
  clickGoodsBtn() {
    wx.navigateTo({
      url: '/pages/goods/goods'
    })
  },
  onReachBottom() {
    if (!this.data.loading ) {
      this.setData({ loading:true})
        let goodsList=this.data.goodsList;
        setTimeout(()=>{
          this.setData({
            goodsList: goodsList.concat(goodsList)
          })
          this.setData({ loading: false })
        },3000)
    }
  },
  onLoad:function () {
    let _this=this;
    wx.request({
      url: 'https://du.hupu.com/mapi/menu/shopping?limit=20&lastId=&sign=f75e0b02496fddf5ba2bb3fd2ca5e052', //仅为示例，并非真实的接口地址
      data:{}, 
      header: {
        'content-type': 'application/x-www-form-urlencoded', // 默认值
        'AppId': 'wxapp',
        'appVersion': '3.4.7',
        'Wxapp-Login-Token': '3b280242|55469d28a9d20e505f49a46790ad38d8|b3b0ee7b|e30a4bf1'
      },
      success(res) { 
        console.log(res.data)
        const resData=res.data.data;
        _this.setData({
          banner: resData.banner,
          goods8: resData.seriesList,
          goods4: resData.recommendList,
          goodsList:resData.hotList
        })
      }
    })
  }
})
